/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.hibernate.model;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "ACCT_USER_ROLE")
public class AcctUserRole extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "AcctUserRole";
	public static final String ALIAS_USER_ID = "用户标识";
	public static final String ALIAS_ROLE_ID = "角色标识";
	
	//date formats
	

	private Long id;
	private Long userId;
	private Long roleId;
	public AcctUserRole(){
	}
	public AcctUserRole(Long id) {
		this.id = id;
	}
	
	@Id 
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 19)
	public Long getId() {
		return this.id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(name = "USER_ID", unique = false, nullable = false, insertable = false, updatable = false, length = 20)
    public Long getUserId() {
        return this.userId;
    }
    
    public void setUserId(Long value) {
        this.userId = value;
    }
    
    @Column(name = "ROLE_ID", unique = false, nullable = false, insertable = false, updatable = false, length = 20)
    public Long getRoleId() {
        return this.roleId;
    }
    
    public void setRoleId(Long value) {
        this.roleId = value;
    }
	
	private AcctRole acctRole;
	public void setAcctRole(AcctRole acctRole){
		this.acctRole = acctRole;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "ROLE_ID",nullable = false, insertable = true, updatable = true) 
	})
	public AcctRole getAcctRole() {
		return acctRole;
	}
	
	private AcctUser acctUser;
	public void setAcctUser(AcctUser acctUser){
		this.acctUser = acctUser;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "USER_ID",nullable = false, insertable = true, updatable = true) 
	})
	public AcctUser getAcctUser() {
		return acctUser;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.toString();
	}
	
 
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof AdPlan == false) return false;
		if(this == obj) return true;
		AdPlan other = (AdPlan)obj;
		return new EqualsBuilder()
			.append(getId(),other.getId())
			.isEquals();
	}
	
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "用户角色";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getId();
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return "ACCT_USER_ROLE" + getId();
	}
}

